package com.example.yijian.edit.timelineEditor;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.example.yijian.utils.LogUtils;
import com.example.yijian.utils.ScreenUtils;
import com.example.yijian.utils.ToastUtil;
import com.meicam.sdk.NvsAVFileInfo;
import com.meicam.sdk.NvsIconGenerator;
import com.meicam.sdk.NvsRational;
import com.meicam.sdk.NvsStreamingContext;
import com.meicam.sdk.NvsUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.BiConsumer;
import java.util.function.Predicate;

public class MultiThumbnailSequenceView extends HorizontalScrollView implements NvsIconGenerator.IconCallback {
    private static final String TAG = "Meicam";
    private NvsIconGenerator m_iconGenerator = null;
    private boolean m_scrollEnabled = true;
    public static final int THUMBNAIL_IMAGE_FILLMODE_STRETCH = 0;
    public static final int THUMBNAIL_IMAGE_FILLMODE_ASPECTCROP = 1;
    private static final int THUMBNAIL_SEQUENCE_FLAGS_CACHED_KEYFRAME_ONLY = 1;
    private static final int THUMBNAIL_SEQUENCE_FLAGS_CACHED_KEYFRAME_ONLY_VALID = 2;
    private MultiThumbnailSequenceView.OnScrollChangeListener m_scrollChangeListener;
    private ArrayList<MultiThumbnailSequenceView.ThumbnailSequenceDesc> m_descArray;
    private float m_thumbnailAspectRatio = 0.5625F;
    private double m_pixelPerMicrosecond = 7.2E-5D;
    private int m_startPadding = 0;
    private int m_endPadding = 0;
    private int m_thumbnailImageFillMode = 0;
    private long m_maxTimelinePosToScroll = 0L;
    private ArrayList<MultiThumbnailSequenceView.ThumbnailSequence> m_thumbnailSequenceArray = new ArrayList();
    private TreeMap<Integer, MultiThumbnailSequenceView.ThumbnailSequence> m_thumbnailSequenceMap = new TreeMap();
    private int m_contentWidth = 0;
    private TreeMap<MultiThumbnailSequenceView.ThumbnailId, MultiThumbnailSequenceView.Thumbnail> m_thumbnailMap = new TreeMap();
    Bitmap m_placeholderBitmap;
    private int m_maxThumbnailWidth = 0;
    private boolean m_updatingThumbnail = false;
    private MultiThumbnailSequenceView.ContentView m_contentView;

    private int thumbHeight;

    public MultiThumbnailSequenceView(Context var1) {
        super(var1);
        NvsUtils.checkFunctionInMainThread();
        this.init(var1);
    }

    public MultiThumbnailSequenceView(Context var1, AttributeSet var2) {
        super(var1, var2);
        NvsUtils.checkFunctionInMainThread();
        this.init(var1);
    }

    public MultiThumbnailSequenceView(Context var1, AttributeSet var2, int var3) {
        super(var1, var2, var3);
        NvsUtils.checkFunctionInMainThread();
        this.init(var1);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public MultiThumbnailSequenceView(Context var1, AttributeSet var2, int var3, int var4) {
        super(var1, var2, var3, var4);
        NvsUtils.checkFunctionInMainThread();
        this.init(var1);
    }

    public ContentView getContentView() {
        return m_contentView;
    }

    public void setThumbnailSequenceDescArray(ArrayList<MultiThumbnailSequenceView.ThumbnailSequenceDesc> sequenceDesc) {
        NvsUtils.checkFunctionInMainThread();
        if (sequenceDesc != this.m_descArray) {
            this.clearThumbnailSequences();
            this.m_placeholderBitmap = null;
            this.m_descArray = sequenceDesc;
            if (sequenceDesc != null) {
                int var2 = 0;
                long var3 = 0L;
                Iterator var5 = sequenceDesc.iterator();

                label30:
                while(true) {
                    while(true) {
                        if (!var5.hasNext()) {
                            break label30;
                        }

                        MultiThumbnailSequenceView.ThumbnailSequenceDesc var6 = (MultiThumbnailSequenceView.ThumbnailSequenceDesc)var5.next();
                        if (var6.mediaFilePath != null && var6.inPoint >= var3 && var6.outPoint > var6.inPoint && var6.trimIn >= 0L && var6.trimOut > var6.trimIn) {
                            MultiThumbnailSequenceView.ThumbnailSequence var7 = new MultiThumbnailSequenceView.ThumbnailSequence();
                            var7.m_index = var2++;
                            var7.m_mediaFilePath = var6.mediaFilePath;
                            var7.m_inPoint = var6.inPoint;
                            var7.m_outPoint = var6.outPoint;
                            var7.m_trimIn = var6.trimIn;
                            var7.m_trimDuration = var6.trimOut - var6.trimIn;
                            var7.m_stillImageHint = var6.stillImageHint;
                            var7.m_onlyDecodeKeyFrame = var6.onlyDecodeKeyFrame;
                            var7.m_thumbnailAspectRatio = var6.thumbnailAspectRatio;
                            this.m_thumbnailSequenceArray.add(var7);
                            var3 = var6.outPoint;
                        } else {
                            Log.e("Meicam", "Invalid ThumbnailSequenceDesc!");
                        }
                    }
                }
            }

            this.updateThumbnailSequenceGeometry();
        }
    }


    public ArrayList<MultiThumbnailSequenceView.ThumbnailSequenceDesc> getThumbnailSequenceDescArray() {
        return this.m_descArray;
    }

    public void setThumbnailImageFillMode(int var1) {
        NvsUtils.checkFunctionInMainThread();
        if (this.m_thumbnailImageFillMode != 1 && this.m_thumbnailImageFillMode != 0) {
            this.m_thumbnailImageFillMode = 0;
        }

        if (this.m_thumbnailImageFillMode != var1) {
            this.m_thumbnailImageFillMode = var1;
            this.updateThumbnailSequenceGeometry();
        }
    }

    public int getThumbnailImageFillMode() {
        return this.m_thumbnailImageFillMode;
    }

    public void setThumbnailAspectRatio(float var1) {
        NvsUtils.checkFunctionInMainThread();
        if (var1 < 0.1F) {
            var1 = 0.1F;
        } else if (var1 > 10.0F) {
            var1 = 10.0F;
        }

        if (Math.abs(this.m_thumbnailAspectRatio - var1) >= 0.001F) {
            this.m_thumbnailAspectRatio = var1;
            this.updateThumbnailSequenceGeometry();
        }
    }

    public float getThumbnailAspectRatio() {
        return this.m_thumbnailAspectRatio;
    }

    public void setPixelPerMicrosecond(double var1) {
        NvsUtils.checkFunctionInMainThread();
        if (var1 > 0.0D && var1 != this.m_pixelPerMicrosecond) {
            this.m_pixelPerMicrosecond = var1;
            this.updateThumbnailSequenceGeometry();
        }
    }

    public double getPixelPerMicrosecond() {
        return this.m_pixelPerMicrosecond;
    }

    public void setStartPadding(int var1) {
        NvsUtils.checkFunctionInMainThread();
        if (var1 >= 0 && var1 != this.m_startPadding) {
            this.m_startPadding = var1;
            this.updateThumbnailSequenceGeometry();
        }
    }

    public int getStartPadding() {
        return this.m_startPadding;
    }

    public void setEndPadding(int var1) {
        NvsUtils.checkFunctionInMainThread();
        if (var1 >= 0 && var1 != this.m_endPadding) {
            this.m_endPadding = var1;
            this.updateThumbnailSequenceGeometry();
        }
    }

    public int getEndPadding() {
        return this.m_endPadding;
    }

    public void setMaxTimelinePosToScroll(int var1) {
        NvsUtils.checkFunctionInMainThread();
        var1 = Math.max(var1, 0);
        if ((long)var1 != this.m_maxTimelinePosToScroll) {
            this.m_maxTimelinePosToScroll = (long)var1;
            this.updateThumbnailSequenceGeometry();
        }
    }

    public long getMaxTimelinePosToScroll() {
        return this.m_maxTimelinePosToScroll;
    }

    public long mapTimelinePosFromX(int var1) {
        NvsUtils.checkFunctionInMainThread();
        int var2 = this.getScrollX();
        var1 = var1 + var2 - this.m_startPadding;
        long var3 = (long)Math.floor((double)var1 / this.m_pixelPerMicrosecond + 0.5D);
        return var3;
    }
    public long mapTimelineExtPosFromX(int var1) {
        NvsUtils.checkFunctionInMainThread();
        int var2 = this.getScrollX();
        long var3 = (long)Math.floor((double)var1 / this.m_pixelPerMicrosecond + 0.5D);
        return var3;
    }

    public int mapXFromTimelinePos(long var1) {
        NvsUtils.checkFunctionInMainThread();
        int var3 = (int)Math.floor((double)var1 * this.m_pixelPerMicrosecond + 0.5D);
        int var4 = this.getScrollX();
        return var3 + this.m_startPadding - var4;
    }

    public void scaleWithAnchor(double var1, int var3) {
        NvsUtils.checkFunctionInMainThread();
        if (var1 > 0.0D) {
            long var4 = this.mapTimelinePosFromX(var3);
            this.m_pixelPerMicrosecond *= var1;
            this.updateThumbnailSequenceGeometry();
            int var6 = this.mapXFromTimelinePos(var4);
            int var7 = this.getScrollX() + var6 - var3;
            this.scrollTo(var7, 0);
        }
    }

    public void setOnScrollChangeListenser(MultiThumbnailSequenceView.OnScrollChangeListener var1) {
        NvsUtils.checkFunctionInMainThread();
        this.m_scrollChangeListener = var1;
    }

    public MultiThumbnailSequenceView.OnScrollChangeListener getOnScrollChangeListenser() {
        NvsUtils.checkFunctionInMainThread();
        return this.m_scrollChangeListener;
    }

    public void setScrollEnabled(boolean var1) {
        this.m_scrollEnabled = var1;
    }

    public boolean getScrollEnabled() {
        return this.m_scrollEnabled;
    }

    protected void onSizeChanged(int var1, int var2, int var3, int var4) {
        super.onSizeChanged(var1, var2, var3, var4);
    }

    protected void onLayout(boolean var1, int var2, int var3, int var4, int var5) {
        super.onLayout(var1, var2, var3, var4, var5);
    }

    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (!this.isInEditMode()) {
            this.m_iconGenerator = new NvsIconGenerator();
            this.m_iconGenerator.setIconCallback(this);
        }

    }

    protected void onDetachedFromWindow() {
        this.cancelIconTask();
        this.m_scrollChangeListener = null;
        if (this.m_iconGenerator != null) {
            this.m_iconGenerator.release();
            this.m_iconGenerator = null;
        }

        super.onDetachedFromWindow();
    }

    protected void onScrollChanged(int var1, int var2, int var3, int var4) {
        super.onScrollChanged(var1, var2, var3, var4);
        if (this.m_scrollChangeListener != null) {
            this.m_scrollChangeListener.onScrollChanged(this, var1, var3);
        }

        this.updateThumbnails();
    }

    public boolean onInterceptTouchEvent(MotionEvent var1) {
        return this.m_scrollEnabled ? super.onInterceptTouchEvent(var1) : false;
    }

    public boolean onTouchEvent(MotionEvent var1) {
        return this.m_scrollEnabled ? super.onTouchEvent(var1) : false;
    }

    private void init(Context var1) {
        this.setVerticalScrollBarEnabled(false);
        this.setHorizontalScrollBarEnabled(false);
        this.m_contentView = new MultiThumbnailSequenceView.ContentView(var1);
        thumbHeight = ScreenUtils.dip2px(var1, 40);
        this.addView(this.m_contentView, new LayoutParams(-2, thumbHeight));
    }

    private void requestUpdateThumbnailSequenceGeometry() {
        (new Handler()).post(new Runnable() {
            public void run() {
                MultiThumbnailSequenceView.this.updateThumbnailSequenceGeometry();
            }
        });
    }

    private void updateThumbnailSequenceGeometry() {
        this.cancelIconTask();
        this.clearThumbnails();
        int var1 = thumbHeight;
        if (var1 != 0) {
            this.m_thumbnailSequenceMap.clear();
            int var2 = this.m_startPadding;
            this.m_maxThumbnailWidth = 0;
            Iterator var3 = this.m_thumbnailSequenceArray.iterator();

            while(var3.hasNext()) {
                MultiThumbnailSequenceView.ThumbnailSequence var4 = (MultiThumbnailSequenceView.ThumbnailSequence)var3.next();
                var4.m_flags &= -3;
                int var5 = (int)Math.floor((double)var4.m_inPoint * this.m_pixelPerMicrosecond + 0.5D) + this.m_startPadding;
                int var6 = (int)Math.floor((double)var4.m_outPoint * this.m_pixelPerMicrosecond + 0.5D) + this.m_startPadding;
                if (var6 > var5) {
                    var4.m_x = var5;
                    var4.m_width = var6 - var5;
                    float var7 = var4.m_thumbnailAspectRatio > 0.0F ? var4.m_thumbnailAspectRatio : this.m_thumbnailAspectRatio;
                    var4.m_thumbnailWidth = (int)Math.floor((double)((float)var1 * var7) + 0.5D);
                    var4.m_thumbnailWidth = Math.max(var4.m_thumbnailWidth, 1);
                    this.m_maxThumbnailWidth = Math.max(var4.m_thumbnailWidth, this.m_maxThumbnailWidth);
                    this.m_thumbnailSequenceMap.put(var5, var4);
                    var2 = var6;
                }
            }

            int var8 = var2;
            int var9;
            if (this.m_maxTimelinePosToScroll <= 0L) {
                var8 = var2 + this.m_endPadding;
            } else {
                var9 = (int)Math.floor((double)this.m_startPadding + (double)this.m_maxTimelinePosToScroll * this.m_pixelPerMicrosecond + 0.5D);
                if (var9 < var2) {
                    var8 = var9;
                }
            }

            this.m_contentWidth = var8;
            this.m_contentView.layout(0, 0, this.m_contentWidth, thumbHeight);
            this.m_contentView.requestLayout();
            if (this.getWidth() + this.getScrollX() > this.m_contentWidth) {
                var9 = Math.max(this.getScrollX() - (this.getWidth() + this.getScrollX() - this.m_contentWidth), 0);
                if (var9 != this.getScrollX()) {
                    this.scrollTo(var9, 0);
                }
            }

        }
    }

    public void updateThumbnails() {
        if (this.m_iconGenerator != null) {
            if (this.m_thumbnailSequenceMap.isEmpty()) {
                this.clearThumbnails();
            } else {
                int maxThumbnailWidth = this.m_maxThumbnailWidth;
                int scrollX = this.getScrollX();
                int var3 = this.getWidth();
                int var4 = Math.max(scrollX - maxThumbnailWidth, this.m_startPadding);
                int var5 = var4 + var3 + maxThumbnailWidth;
                if (var5 <= var4) {
                    this.clearThumbnails();
                } else {
                    Integer var6 = (Integer)this.m_thumbnailSequenceMap.floorKey(var4);
                    if (var6 == null) {
                        var6 = (Integer)this.m_thumbnailSequenceMap.firstKey();
                    }

                    SortedMap var7 = this.m_thumbnailSequenceMap.tailMap(var6);
                    Iterator var8 = var7.entrySet().iterator();

                    while(var8.hasNext()) {
                        Map.Entry var9 = (Map.Entry)var8.next();
                        MultiThumbnailSequenceView.ThumbnailSequence var10 = (MultiThumbnailSequenceView.ThumbnailSequence)var9.getValue();
                        if (var10.m_x + var10.m_width >= var4) {
                            if (var10.m_x >= var5) {
                                break;
                            }

                            int var11;
                            if (var10.m_x < var4) {
                                var11 = var10.m_x + (var4 - var10.m_x) / var10.m_thumbnailWidth * var10.m_thumbnailWidth;
                            } else {
                                var11 = var10.m_x;
                            }

                            boolean var12 = false;

                            int var14;
                            for(int var13 = var10.m_x + var10.m_width; var11 < var13; var11 += var14) {
                                if (var11 >= var5) {
                                    var12 = true;
                                    break;
                                }

                                var14 = var10.m_thumbnailWidth;
                                if (var11 + var14 > var13) {
                                    var14 = var13 - var11;
                                }

                                long var15 = var10.calcTimestampFromX(var11);
                                MultiThumbnailSequenceView.ThumbnailId var17 = new MultiThumbnailSequenceView.ThumbnailId(var10.m_index, var15);
                                MultiThumbnailSequenceView.Thumbnail var18 = (MultiThumbnailSequenceView.Thumbnail)this.m_thumbnailMap.get(var17);
                                if (var18 == null) {
                                    var18 = new MultiThumbnailSequenceView.Thumbnail();
                                    var18.m_owner = var10;
                                    var18.m_timestamp = var15;
                                    var18.m_imageViewUpToDate = false;
                                    var18.m_touched = true;
                                    this.m_thumbnailMap.put(var17, var18);
                                    if (var14 == var10.m_thumbnailWidth) {
                                        var18.m_imageView = new ImageView(this.getContext());
                                    } else {
                                        var18.m_imageView = new MultiThumbnailSequenceView.ClipImageView(this.getContext(), var14);
                                    }

                                    if (this.m_thumbnailImageFillMode == 0) {
                                        var18.m_imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                                    } else if (this.m_thumbnailImageFillMode == 1) {
                                        var18.m_imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                                    }

                                    this.m_contentView.addView(var18.m_imageView);
                                    var18.m_imageView.layout(var11, 0, var11 + var10.m_thumbnailWidth, this.m_contentView.getHeight());
                                } else {
                                    var18.m_touched = true;
                                }
                            }

                            if (var12) {
                                break;
                            }
                        }
                    }

                    this.m_updatingThumbnail = true;
                    boolean var19 = false;
                    TreeMap var20 = new TreeMap();
                    Set var21 = this.m_thumbnailMap.entrySet();
                    Iterator var22 = var21.iterator();

                    while(var22.hasNext()) {
                        Map.Entry var23 = (Map.Entry)var22.next();
                        MultiThumbnailSequenceView.Thumbnail var24 = (MultiThumbnailSequenceView.Thumbnail)var23.getValue();
                        if (var24.m_imageView != null) {
                            Drawable var27 = var24.m_imageView.getDrawable();
                            if (var27 != null) {
                                Bitmap var28 = ((BitmapDrawable)var27).getBitmap();
                                if (var28 != null) {
                                    this.m_placeholderBitmap = var28;
                                }
                            }
                        }

                        if (!var24.m_touched) {
                            if (var24.m_iconTaskId != 0L) {
                                this.m_iconGenerator.cancelTask(var24.m_iconTaskId);
                            }

                            this.m_contentView.removeView(var24.m_imageView);
                            var22.remove();
                        } else {
                            var24.m_touched = false;
                            if (var24.m_imageViewUpToDate) {
                                Bitmap var29 = ((BitmapDrawable)var24.m_imageView.getDrawable()).getBitmap();
                                var20.put((MultiThumbnailSequenceView.ThumbnailId)var23.getKey(), var29);
                            } else {
                                long var31 = var24.m_owner.m_stillImageHint ? 0L : var24.m_timestamp;
                                this.updateKeyframeOnlyModeForThumbnailSequence(var24.m_owner);
                                int var16 = (var24.m_owner.m_flags & 1) != 0 ? 1 : 0;
                                Bitmap var33 = this.m_iconGenerator.getIconFromCache(var24.m_owner.m_mediaFilePath, var31, var16);
                                if (var33 != null) {
                                    var20.put((MultiThumbnailSequenceView.ThumbnailId)var23.getKey(), var33);
                                    if (this.setBitmapToThumbnail(var33, var24)) {
                                        var24.m_imageViewUpToDate = true;
                                        var24.m_iconTaskId = 0L;
                                    }
                                } else {
                                    var19 = true;
                                    var24.m_iconTaskId = this.m_iconGenerator.getIcon(var24.m_owner.m_mediaFilePath, var31, var16);
                                }
                            }
                        }
                    }

                    this.m_updatingThumbnail = false;
                    if (var19) {
                        Iterator var25;
                        Map.Entry var26;
                        MultiThumbnailSequenceView.Thumbnail var32;
                        if (!var20.isEmpty()) {
                            var25 = this.m_thumbnailMap.entrySet().iterator();

                            while(var25.hasNext()) {
                                var26 = (Map.Entry)var25.next();
                                var32 = (MultiThumbnailSequenceView.Thumbnail)var26.getValue();
                                if (!var32.m_imageViewUpToDate) {
                                    Map.Entry var30 = var20.ceilingEntry((MultiThumbnailSequenceView.ThumbnailId)var26.getKey());
                                    if (var30 != null) {
                                        this.setBitmapToThumbnail((Bitmap)var30.getValue(), var32);
                                    } else {
                                        this.setBitmapToThumbnail((Bitmap)var20.lastEntry().getValue(), var32);
                                    }
                                }
                            }

                        } else {
                            if (this.m_placeholderBitmap != null) {
                                var25 = this.m_thumbnailMap.entrySet().iterator();

                                while(var25.hasNext()) {
                                    var26 = (Map.Entry)var25.next();
                                    var32 = (MultiThumbnailSequenceView.Thumbnail)var26.getValue();
                                    if (!var32.m_imageViewUpToDate) {
                                        this.setBitmapToThumbnail(this.m_placeholderBitmap, var32);
                                    }
                                }
                            }

                        }
                    }
                }
            }
        }
    }

    private void updateKeyframeOnlyModeForThumbnailSequence(MultiThumbnailSequenceView.ThumbnailSequence var1) {
        if ((var1.m_flags & 2) == 0) {
            if (var1.m_onlyDecodeKeyFrame) {
                var1.m_flags |= 3;
            } else {
                long var2 = Math.max((long)((double)var1.m_thumbnailWidth / this.m_pixelPerMicrosecond + 0.5D), 1L);
                boolean var4 = this.shouldDecodecKeyFrameOnly(var1.m_mediaFilePath, var2);
                if (var4) {
                    var1.m_flags |= 1;
                } else {
                    var1.m_flags &= -2;
                }

                var1.m_flags |= 2;
            }
        }
    }

    private boolean shouldDecodecKeyFrameOnly(String var1, long var2) {
        NvsStreamingContext var4 = NvsStreamingContext.getInstance();
        if (var4 == null) {
            return false;
        } else {
            NvsAVFileInfo var5 = var4.getAVFileInfo(var1);
            if (var5 == null) {
                return false;
            } else if (var5.getVideoStreamCount() < 1) {
                return false;
            } else {
                NvsRational var6 = var5.getVideoStreamFrameRate(0);
                if (var6 == null) {
                    return false;
                } else if (var6.den > 0 && var6.num > 0) {
                    long var7 = var5.getVideoStreamDuration(0);
                    if (var7 < var2) {
                        return false;
                    } else {
                        int var9 = var4.detectVideoFileKeyframeInterval(var1);
                        if (var9 == 0) {
                            var9 = 30;
                        } else if (var9 == 1) {
                            return false;
                        }

                        int var10 = (int)((double)var9 * ((double)var6.den / (double)var6.num) * 1000000.0D);
                        if (var9 <= 30) {
                            return false;
                        } else {
                            if (var9 <= 60) {
                                if ((double)var2 > (double)var10 * 0.8D) {
                                    return true;
                                }
                            } else if (var9 <= 100) {
                                if ((double)var2 > (double)var10 * 0.7D) {
                                    return true;
                                }
                            } else if (var9 <= 150) {
                                if ((double)var2 > (double)var10 * 0.5D) {
                                    return true;
                                }
                            } else if (var9 <= 250) {
                                if ((double)var2 > (double)var10 * 0.3D) {
                                    return true;
                                }
                            } else if ((double)var2 > (double)var10 * 0.2D) {
                                return true;
                            }

                            return false;
                        }
                    }
                } else {
                    return false;
                }
            }
        }
    }

    private boolean setBitmapToThumbnail(Bitmap var1, MultiThumbnailSequenceView.Thumbnail var2) {
        if (var1 != null && var2.m_imageView != null) {
            var2.m_imageView.setImageBitmap(var1);
            return true;
        } else {
            return false;
        }
    }

    private void clearThumbnailSequences() {
        this.cancelIconTask();
        this.clearThumbnails();
        this.m_thumbnailSequenceArray.clear();
        this.m_thumbnailSequenceMap.clear();
        this.m_contentWidth = 0;
    }

    private void clearThumbnails() {
        Iterator var1 = this.m_thumbnailMap.entrySet().iterator();

        while(var1.hasNext()) {
            Map.Entry var2 = (Map.Entry)var1.next();
            this.m_contentView.removeView(((MultiThumbnailSequenceView.Thumbnail)var2.getValue()).m_imageView);
        }

        this.m_thumbnailMap.clear();
    }

    private void cancelIconTask() {
        if (this.m_iconGenerator != null) {
            this.m_iconGenerator.cancelTask(0L);
        }

    }

    public void onIconReady(Bitmap var1, long var2, long var4) {
        if (!this.m_updatingThumbnail) {
            this.updateThumbnails();
        } else {
            (new Handler()).post(new Runnable() {
                public void run() {
                    MultiThumbnailSequenceView.this.updateThumbnails();
                }
            });
        }

    }

    private static class ClipImageView extends androidx.appcompat.widget.AppCompatImageView {
        private int m_clipWidth;

        ClipImageView(Context var1, int var2) {
            super(var1);
            this.m_clipWidth = var2;
        }

        protected void onDraw(Canvas var1) {
            var1.clipRect(new Rect(0, 0, this.m_clipWidth, this.getHeight()));
            super.onDraw(var1);
        }
    }

    public class ContentView extends ViewGroup {


        public ContentView(Context var2) {
            super(var2);
        }

        public boolean shouldDelayChildPressedState() {
            return false;
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int contentWidth = MultiThumbnailSequenceView.this.m_contentWidth;
            int mode = MeasureSpec.getMode(heightMeasureSpec);
            int size = MeasureSpec.getSize(heightMeasureSpec);
            int height;
            if (mode != 1073741824 && mode != -2147483648) {
                height = MultiThumbnailSequenceView.this.getHeight();
            } else {
                height = size;
            }

            contentWidth = Math.max(contentWidth, this.getSuggestedMinimumWidth());
            height = Math.max(height, this.getSuggestedMinimumHeight());
            contentWidth = resolveSizeAndState(contentWidth, widthMeasureSpec, 0);
            height = resolveSizeAndState(height, heightMeasureSpec, 0);
            this.setMeasuredDimension(contentWidth, height);
        }

        protected void onLayout(boolean var1, int var2, int var3, int var4, int var5) {
            MultiThumbnailSequenceView.this.updateThumbnails();
        }

        protected void onSizeChanged(int var1, int var2, int var3, int var4) {
            if (var2 != var4) {
                MultiThumbnailSequenceView.this.requestUpdateThumbnailSequenceGeometry();
            }

            super.onSizeChanged(var1, var2, var3, var4);
        }
    }

    private static class Thumbnail {
        MultiThumbnailSequenceView.ThumbnailSequence m_owner;
        long m_timestamp = 0L;
        ImageView m_imageView;
        long m_iconTaskId = 0L;
        boolean m_imageViewUpToDate = false;
        boolean m_touched = false;

        public Thumbnail() {
        }
    }

    private static class ThumbnailId implements Comparable<MultiThumbnailSequenceView.ThumbnailId> {
        public int m_seqIndex;
        public long m_timestamp;

        public ThumbnailId(int var1, long var2) {
            this.m_seqIndex = var1;
            this.m_timestamp = var2;
        }

        public int compareTo(MultiThumbnailSequenceView.ThumbnailId var1) {
            if (this.m_seqIndex < var1.m_seqIndex) {
                return -1;
            } else if (this.m_seqIndex > var1.m_seqIndex) {
                return 1;
            } else if (this.m_timestamp < var1.m_timestamp) {
                return -1;
            } else {
                return this.m_timestamp > var1.m_timestamp ? 1 : 0;
            }
        }
    }

    private static class ThumbnailSequence {
        int m_index = 0;
        String m_mediaFilePath;
        long m_inPoint = 0L;
        long m_outPoint = 0L;
        long m_trimIn = 0L;
        long m_trimDuration = 0L;
        boolean m_stillImageHint = false;
        boolean m_onlyDecodeKeyFrame = false;
        public float m_thumbnailAspectRatio = 0.0F;
        int m_flags = 0;
        int m_x = 0;
        int m_width = 0;
        int m_thumbnailWidth = 0;

        public ThumbnailSequence() {
        }

        public long calcTimestampFromX(int var1) {
            return this.m_trimIn + (long)Math.floor((double)(var1 - this.m_x) / (double)this.m_width * (double)this.m_trimDuration + 0.5D);
        }
    }

    public static class ThumbnailSequenceDesc {
        public String mediaFilePath;
        public long inPoint = 0L;
        public long outPoint = 4000000L;
        public long trimIn = 0L;
        public long trimOut = 4000000L;
        public boolean stillImageHint = false;
        public boolean onlyDecodeKeyFrame = false;
        public float thumbnailAspectRatio = 0.0F;

        public ThumbnailSequenceDesc() {
        }
    }

    public interface OnScrollChangeListener {
        void onScrollChanged(MultiThumbnailSequenceView var1, int var2, int var3);
    }
}